

import 'package:flutter/material.dart';
import 'package:untitled/pages/Getx_project/ShopClassBean.dart';
import 'package:get/get.dart';
import 'package:untitled/pages/Getx_project/ShopController.dart';

class ShopItemWidget extends StatefulWidget {
  final GoodsBean goodsBean;
  ShopItemWidget(this.goodsBean);

  @override
  State<ShopItemWidget> createState() => _ShopItemWidgetState();
}

class _ShopItemWidgetState extends State<ShopItemWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(top: 10),
      padding: EdgeInsets.all(14),
      child: Container(
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            // 左侧的图片
            Container(
              child: Icon(Icons.one_k),
              width: 100,
              height: 100,
              margin: EdgeInsets.only(right: 16),
              color: Colors.grey[200],
            ),
            // 右侧的文本
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text("${widget.goodsBean.title}"),
                  Text("${widget.goodsBean.subTitle}"),
                  Row(
                    mainAxisAlignment:MainAxisAlignment.end,
                    children: [
                      TextButton(
                        onPressed: (){
                          Get.find<ShopController>().addCard(widget.goodsBean);
                          setState(() {
                            widget.goodsBean.isCard = !widget.goodsBean.isCard;
                          });
                        }, 
                        child: Text(widget.goodsBean.isCard?"移出购物车":"加入购物车"))
                    ],
                  )
                ],
              ),
            )
          ],
        ),
      ),
    );
    
  }
}